home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 October: Mac OS SDK / Dev.CD Oct 00 SDK1.toast / Development Kits / Mac OS / AIAT / Headers / Storage / IAMutex.h < prev    next >
Encoding:
Text File  |  1998-04-16  |  1.5 KB  |  61 lines  |  [TEXT/CWIE]

  1. // IAMutex.h
  2. //    Copyright:    © 1994 - 1998 by Apple Computer, Inc., all rights reserved.
  3.  
  4.  
  5. // Interface to mutexes (MUtual EXclusion semaphors) used by IA library.
  6. // Applications simply subclass IAMutex and set IANewMutex
  7. // to make IA code thread-safe for the application's threads.
  8.  
  9. #pragma once
  10. #ifndef IAMutex_h
  11. #define IAMutex_h
  12.  
  13. #pragma import on
  14.  
  15. #if PRAGMA_STRUCT_ALIGN
  16.     #pragma options align=power
  17. #endif
  18.  
  19. #include "IACommon.h"
  20.  
  21. #include <stdlib.h>
  22.  
  23. #pragma IA_BEGIN_EXPORTS
  24.  
  25. class IAMutex {                                    // base class for mutexes
  26. public:
  27.     virtual            ~IAMutex();                    // no-op
  28.     virtual void    Lock() = 0;                    // returns when we have control of the mutex
  29.     virtual void    Unlock() = 0;                // releases control of the mutex
  30. };
  31.  
  32. typedef IAMutex*            IAMutexConstructor();
  33. IAMutex*                    IADefaultMutexConstructor();    // no-op mutex implementation
  34.  
  35. // IANewMutex is used by IA code to create new mutexes.
  36. // Applications should reset this to use a different mutex implementation.
  37. // By default it is set to &IADefaultMutexConstructor, appropriate for single-threaded apps.
  38. extern IAMutexConstructor*    IANewMutex;
  39.  
  40. // Locks a mutex for the duration of its stack-allocated life.
  41. // The typical usage is:
  42. //   { IALock lock(mutex);
  43. //     ... code that needs to run locked ... }
  44. class IALock {
  45. public:
  46.     IALock(IAMutex* mutex);                        // locks the mutex
  47.     ~IALock(void);                                // unlocks the mutex
  48. private:
  49.     IAMutex            *mutex;
  50.     void*            operator new(size_t size);    // stack allocate only
  51. };
  52.  
  53. #pragma IA_END_EXPORTS
  54.  
  55. #if PRAGMA_STRUCT_ALIGN
  56.     #pragma options align=reset
  57. #endif
  58.  
  59. #pragma import reset
  60. #endif
  61.